//
//  RFAImageViewingController.m
//  RFA Manager
//
//  Created by Torsten Kammer on 19.03.08.
//  Copyright 2008 Ferroequinologist.de. All rights reserved.
//

#import "RFAImageViewingController.h"
#import "RFATreeNode.h"
#import "PropertyCategories.h"

@implementation RFAImageViewingController

+ (void)initialize
{
	static BOOL initialized = NO;
	if (initialized) return;
	initialized = YES;
	
	[self exposeBinding:@"image"];
}

- (id)initWithArchiveEntry:(RFATreeNode *)entry;
{
	if (![super initWithWindowNibName:@"TextureViewing"]) return nil;
	archiveEntry = entry;
	[self bind:@"image" toObject:archiveEntry withKeyPath:@"image" options:nil];
	[archiveEntry addObserver:self forKeyPath:@"data" options:NSKeyValueObservingOptionNew context:NULL];
    
	return self;
}

@synthesize archiveEntry;


- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName;
{
	// It's got to be an em dash according to Apple HIG
	return [displayName stringByAppendingFormat:@" %C %@", 0x2014, archiveEntry.name];
}

- (NSUndoManager *)undoManagerForTextView:(NSTextView *)view
{
	return [self.document undoManager];
}

- (void)setImage:(NSImage *)anImage
{
	[self willChangeValueForKey:@"image"];
	
	image = anImage;
	
    [self.window setContentSize:image.size];
	self.window.contentMaxSize = image.size;
	self.window.contentAspectRatio = image.size;
	[self didChangeValueForKey:@"image"];
}

- (NSImage *)image
{
	return image;
}

@end
